package com.ruoyi.wechat.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.wechat.common.tree.TreeNode;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 地址选项
 *
 * @author YinHeng
 * @date 2024/2/21 9:11
 */
@Data
@TableName("app_addr_item")
public class AddrItem implements TreeNode<Long, AddrItem> {
    /**
     * 主键
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long id;
    /**
     * 父级ID
     */
    private Long pid;
    /**
     * 部门ID
     */
    private Long deptId;
    /**
     * 所属区域ID
     */
    private String area;
    /**
     * 地名
     */
    private String name;
    /**
     * 祖籍
     */
    private String level;
    /**
     * 驿站标签
     */
    private String labels;

    @TableField(exist = false)
    private List<AddrItem> children;

    @Override
    public List<AddrItem> getChildren() {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        return children;
    }

    @Override
    public void setChildren(List<AddrItem> children) {
        this.children = children;
    }

    @Override
    public void addChild(AddrItem node) {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        this.children.add(node);
    }
}
